/*
 * Copyright 2019-2025 the original author or authors.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * https://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.iiifi.kite.launcher.enums;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 项目启动器，预制的环境变量
 *
 * @author kite@iiifi.com 花朝
 */
@Getter
@AllArgsConstructor
public enum KiteEnv {
    /**
     * dev（开发），默认。
     */
    DEV("dev", "debug", KiteLogLevel.BODY),
    /**
     * test（测试）
     */
    TEST("test", "info", KiteLogLevel.BODY),
    /**
     * other（其他环境）
     */
    OTHER("other", "info", KiteLogLevel.HEADERS),
    /**
     * prod（正式）
     */
    PROD("prod", "warn", KiteLogLevel.NONE);

    /**
     * 等级
     */
    private String name;
    /**
     * log文件的级别
     */
    private String logFileLevel;
    /**
     * 请求日志级别
     */
    private KiteLogLevel reqLogLevel;

    /**
     * 获取环境列表
     *
     * @return 环境列表
     */
    public static List<String> getEnvList() {
        return Arrays.stream(KiteEnv.values())
                .filter(kiteEnv -> !kiteEnv.getName().equals(KiteEnv.OTHER.getName()))
                .map(KiteEnv::getName)
                .collect(Collectors.toList());
    }

    /**
     * 环境转换
     *
     * @return 环境
     */
    public static KiteEnv of(String env) {
        KiteEnv[] values = KiteEnv.values();
        for (KiteEnv kiteEnv : values) {
            if (kiteEnv.name.equals(env)) {
                return kiteEnv;
            }
        }
        return KiteEnv.OTHER;
    }
}
